package com.webchat.aigc.config;

import com.webchat.aigc.consumer.redis.AiBotChatRedisQueueListener;
import com.webchat.aigc.consumer.redis.RobotChatRedisQueueListener;
import com.webchat.common.enums.messagequeue.MessageBroadChannelEnum;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

@Configuration
public class RedisConfig {

    @Resource
    private RobotChatRedisQueueListener robotChatRedisQueueListener;
    @Resource
    private AiBotChatRedisQueueListener aiBotChatRedisQueueListener;

    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory redisConnectionFactory) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        // 设置链接工厂
        container.setConnectionFactory(redisConnectionFactory);
        // 配置消息监听器
        container.addMessageListener(robotChatRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_CHAT_ROBOT.getChannel()));
        container.addMessageListener(aiBotChatRedisQueueListener, new ChannelTopic(MessageBroadChannelEnum.QUEUE_CHAT_AI_BOT.getChannel()));
        return container;
    }
}
